﻿////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// <copyright>Copyright 2008-2011 Andreas Huber Doenni</copyright>
// Distributed under the Microsoft Public License (Ms-PL).
// See accompanying file License.txt or copy at http://mews.codeplex.com/license.
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

namespace Mews
{
    using System;

    /// <summary>Provides helper functions for buffers.</summary>
    internal static class BufferHelper
    {
        internal static void AssertValidRange<T>(
            T[] buffer, string bufferName, int index, string indexName, int count, string countName)
        {
            if (buffer == null)
            {
                throw new ArgumentNullException(bufferName);
            }

            if (index < 0)
            {
                throw new ArgumentOutOfRangeException(indexName, ExceptionMessages.NonnegativeNumberRequired);
            }

            if (count < 0)
            {
                throw new ArgumentOutOfRangeException(countName, ExceptionMessages.NonnegativeNumberRequired);
            }

            if (buffer.Length - index < count)
            {
                throw new ArgumentException(
                    bufferName,
                    indexName + " and " + countName + " must define a range that falls entirely within the buffer.");
            }
        }
    }
}
